// ==UserScript==
// @name video controler
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to control video by keyboard.For example, whitespace to pause or play, left or right arrow to go back or skip
// @author DSY
// @include *://appikkvt28p6757.h5.xiaoeknow.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=xiaoeknow.com
// @updateURL         https://gitee.com/zaiMoe/greasemonkey/raw/master/xiaoerno-video-controler.user.js
// @downloadURL       https://gitee.com/zaiMoe/greasemonkey/raw/master/xiaoerno-video-controler.user.js
// @grant none
// ==/UserScript==

(function() {
    let targetVideo = document.querySelector("video");

    const interval = setInterval(() => {
        if (targetVideo) {
            clearInterval(interval);
        }

        targetVideo = document.querySelector("video");
    }, 1000);

    document.addEventListener("keydown", (e) => {
        if (!targetVideo) {
            return;
        }

        switch (e.key) {
            case "ArrowLeft":
                targetVideo.currentTime -= 10;
                break;
            case "ArrowRight":
                targetVideo.currentTime += 10;
                break;
            case " ":
                targetVideo.paused ? targetVideo.play() : targetVideo.pause();
                break;
        }
    });
})();